﻿using System;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.Diagnostics;

namespace RedirectManager
{
    public static class Config
    {
        public static string[] IgnoredSites
        {
            get
            {
                return StringUtil.Split(Settings.GetSetting("RedirectManager.IgnoredSites", string.Empty), char.Parse("|"), false);
            }
        }

        public static string[] DisplayLinkTypes
        {
            get
            {
                return StringUtil.Split(Settings.GetSetting("RedirectManager.DisplayLinkTypes", string.Empty), char.Parse("|"), false);
            }
        }

        public static string UrlPathValidationExpression
        {
            get
            {
                var expression = Settings.GetSetting("RedirectManager.UrlPathValidation");
                Assert.IsNotNullOrEmpty(expression, "Redirect Manager: UrlPathValidation setting is required");
                return expression;
            }
        }

        public static bool CheckDuplicateUrlOnCreate
        {
            get
            {
                return Settings.GetBoolSetting("RedirectManager.CheckDuplicates", true);
            }
        }

        public static bool SiteContextChecking
        {
            get
            {
                return Settings.GetBoolSetting("RedirectManager.SiteContextChecking", false);
            }
        }

        public static bool LogProcessorStopwatch
        {
            get
            {
                return Settings.GetBoolSetting("RedirectManager.LogProcessorStopwatch", false);
            }
        }

        public static int DisplayMaxLinks
        {
            get
            {
                return Settings.GetIntSetting("RedirectManager.DisplayLinkMaximum", 30);
            }
        }

        public static string StatusDescription301
        {
            get
            {
                return Settings.GetSetting("RedirectManager.StatusDescription.301", "301 Moved Permanently");
            }
        }

        public static string StatusDescription302
        {
            get
            {
                return Settings.GetSetting("RedirectManager.StatusDescription.302", "302 Moved Permanently");
            }
        }

        public static T Convert<T>(string value)
        {
            return (T)Enum.Parse(typeof(T), value, true);
        }
    }
}
